<script setup>
import {ref} from "vue"
import { onLoad } from "@dcloudio/uni-app";
import { httpRequest } from "../../utils/http";
const videoObj = ref('')
onLoad((e)=>{
    videoObj.value = JSON.parse(e.videoObj)
    console.log(videoObj.value);
    console.log(videoObj.value.collect);
})
const goIP = async() => {
    uni.showLoading({
        title: '请稍后',
        mask: false
    })
    const res = await httpRequest("/api/findTaskStart", "POST", {
      businessId: uni.getStorageSync("business").businessId,
    });
    uni.hideLoading()
    console.log(res.data);
    if(res.data&&res.data.start==2)return uni.showToast({title:'正在生成中,请稍后',icon:'none'})
    if(res.data&&res.data.type=='same'&&videoObj.value.popVideoId!=uni.getStorageSync('same').popVideoId){
        uni.showModal({
            title: '提示',
            content: '切换视频会清除草稿，是否继续?',
            showCancel: true,
            success: async({ confirm, cancel }) => {
                if(confirm){
                     //删除临时文件
                  await httpRequest('/api/delStaging','POST',{
                  businessId: uni.getStorageSync("business").businessId,
                })
                //删除任务
                await httpRequest('/api/delTask','POST',{
                  taskId:uni.getStorageSync('taskId')
                })
                uni.removeStorageSync('copy')
                uni.removeStorageSync('maxNum')
                uni.removeStorageSync('time')
                uni.removeStorageSync('v1')
                uni.removeStorageSync('v2')
                uni.removeStorageSync('v3')
                uni.removeStorageSync('v4')
                uni.removeStorageSync('v5')
                uni.removeStorageSync('v6')
                uni.removeStorageSync('v7')
                uni.removeStorageSync('videoArr')
                uni.removeStorageSync('product')
                uni.removeStorageSync('taskId')
                uni.removeStorageSync('percent')
                uni.removeStorageSync('isSlice')
                uni.removeStorageSync('color')
                uni.removeStorageSync('font')
                uni.removeStorageSync('isCross')
                uni.removeStorageSync('voiceArr')
                uni.removeStorageSync('isItem')
                uni.removeStorageSync('templateId')
                uni.removeStorageSync('isSwitch')
                uni.removeStorageSync('same')
                uni.removeStorageSync('sameTitle')
                uni.setStorageSync('same',videoObj.value)
                uni.redirectTo({ url: `/pageA/index/IP?videoObj=${JSON.stringify(videoObj.value)}` })
                }
            }
        })
    }else{
        uni.setStorageSync('same',videoObj.value)
        uni.redirectTo({ url: `/pageA/index/IP?videoObj=${JSON.stringify(videoObj.value)}` })
    }
}
const getNum = (n) => {
    let num = Number(n)
    if(Number(num)>10000)return `${(Number(num)/10000).toFixed(1)}万`
    if(Number(num)>100000000)return `${(Number(num)/100000000).toFixed(1)}亿`
    return num
}
getNum(videoObj.value.collect)
</script>

<template>
  <view class="page">
    <video custom-cache=" { {false}}" class="video" :src="videoObj.popVideoUrl"></video>
    <view class="bottom">
        <view class="data">
            <view class="items">
                <text class="num">{{getNum(videoObj.comment)}}</text>
                <text class="text">播放量</text>
            </view>
            <view class="items">
                <text class="num">{{ getNum(videoObj.digg) }}</text>
                <text class="text">点赞量</text>
            </view>
            <view class="items">
                <text class="num">{{ getNum(videoObj.collect) }}</text>
                <text class="text">使用量</text>
            </view>
        </view>
        <view class="btn">
            <view class="cus" @click="goIP">
                <image style="width: 36rpx;height: 36rpx;margin-right: 6rpx;transform: translateY(2rpx);" src="https://www.diandianyouke.site:801/fileDataBase/static/stag/static/img/home_jjk_icon_jtkuanb.png" mode="" />
                <text>剪同款</text>
            </view>
        </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
    .page{
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: #000;
        .video{
            width: 100%;
            height: 1086rpx;
        }
        .bottom{
            position: fixed;
            bottom: 0;
            left: 0;
            box-sizing: border-box;
            width: 100%;
            height: 362rpx;
            border-radius: 32rpx 32rpx 0 0;
            
            .data{
                box-sizing: border-box;
                display: flex;
                align-items: center;
                justify-content: space-between;
                height: 196rpx;
                background: linear-gradient(180deg,rgb(244,217,255) 0%,rgb(252,253,255)99.5%);
                padding: 36rpx 44rpx;
                border-radius: 32rpx 32rpx 0 0;
                .items{
                    display: flex;
                    flex-direction: column;
                    align-items: center;
                    .num{
                        font-size: 44rpx;
                        color: rgb(142,84,244);
                        margin-bottom: 18rpx;
                        font-weight: 700;
                    }
                    .text{
                        font-size: 28rpx;
                        color: rgb(144,147,153);
                    }
                }
            }
            .btn{
                box-sizing: border-box;
                width: 100%;
                height: 166rpx;
                background-color: #fff;
                padding: 10rpx 30rpx 0;
                .cus{
                    width: 690rpx;
                    height: 88rpx;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    background-color: rgb(142,84,244);
                    border-radius: 8rpx;
                    font-size: 32rpx;
                    color: #fff;
                }
            }
        }
        
    }
</style>
